# -*- coding:utf8 -*-
# __author__ = "zhangying"
# __date__ = "2019/2/18 16:48"
# Appium_Page object设计模式
# Page object设计模式思维，把app按页面去划分，一个页面就是一个page对象
# 每个页面的元素集中管理、页面上按钮操作方法单独封装
#1.调用定位信息

from util.get_by_local import GETBYLOCAl
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from appium import webdriver
from base.base_driver import BaseDriver


# 目的：拿所有页面的配置的元素信息
class Login_Page:
    #获取登陆页面所有的页面元素信息
    def __init__(self,i):
        base_driver = BaseDriver()
        self.driver = base_driver.android_driver(i)
        self.get_by_local = GETBYLOCAl(self.driver)

    def get_usernamer_element(self):
        '''
        获取用户名元素信息
        '''
        return self.get_by_local.get_element('username')

    def get_password_element(self):
        '''
        获取密码的元素信息
        '''
        return self.get_by_local.get_element('password')

    def get_login_button_element(self):
        '''
        获取登陆按钮元素信息
        '''
        return self.get_by_local.get_element('login_button')

    def get_forget_password_element(self):
        '''
        获取忘记密码元素信息
        '''
        return self.get_by_local.get_element('forget_password')

    def get_register_element(self):
        '''
        获取注册按钮元素信息
        :return:
        '''
        return self.get_by_local.get_element('register')

    def get_tost_element(self,message):
        '''
        获取tostelement
        :param message:
        :return:
        '''
        time.sleep(2)
        tost_elemet = ("xpath", "//*[contains(@text,"+message+")]")
        return WebDriverWait(self.driver, 10, 0.1).until(EC.presence_of_all_elements_located(tost_elemet))


